package cn.hubujyjs.lp.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        LoginInterceptor loginInterceptor=new LoginInterceptor();
        RefreshTokenInterceptor refreshTokenInterceptor=new RefreshTokenInterceptor(stringRedisTemplate);
        registry.addInterceptor(loginInterceptor)
                .excludePathPatterns(
                        "/api/user/code",
                        "/api/user/login",
                        "/ssh",
                        "/api/admin/login"
                )
                .order(1);
        registry.addInterceptor(refreshTokenInterceptor)
                .addPathPatterns("/**")  //默认就是拦截所有请求
                .order(0);
    }
}
